package com.example.a429;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

public class MessageActivity extends AppCompatActivity {

    private RecyclerView messageRecyclerView;
    private MessageAdapter messageAdapter;
    private List<MessageItem> messageList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message);
        ImageView backButton = findViewById(R.id.backButton);
        backButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 创建跳转到 MainActivity 的 Intent
                Intent intent = new Intent(MessageActivity.this, MainActivity.class);
                // 启动 MainActivity
                startActivity(intent);
                // 关闭当前 Activity
                finish();
            }
        });


        // 初始化RecyclerView
        messageRecyclerView = findViewById(R.id.messageList);
        messageRecyclerView.setLayoutManager(new LinearLayoutManager(this));

        // 准备消息数据
        messageList = new ArrayList<>();
        messageList.add(new MessageItem(
                R.drawable.ic_notification, "", "您的订单已发货，请注意查收", "12:30", 0, true));
        messageList.add(new MessageItem(
                R.drawable.dengchao, "邓超", "请问这件衣服还在吗？", "11:45", 2, false));
        messageList.add(new MessageItem(
                R.drawable.wuyi, "吴亦凡", "好的，那就这个价格成交", "10:20", 0, false));
        messageList.add(new MessageItem(
                R.drawable.zhangruonan, "章若楠", "这个手机什么时候可以看货？", "昨天", 0, false));
        messageList.add(new MessageItem(
                R.drawable.yangying, "李小姐", "包装很好，商品已收到", "昨天", 0, false));

        // 设置适配器
        messageAdapter = new MessageAdapter(messageList);
        messageRecyclerView.setAdapter(messageAdapter);

    }

}